package com.controller.manager;

  
import java.io.IOException;
  
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.filter.OncePerRequestFilter;

import com.po.AdminBeanW;
/**
 * 登录过滤器
 * @author wangli
 *
 */

public class SessionFilter extends OncePerRequestFilter {
  
   
    @Override
    protected void doFilterInternal(HttpServletRequest request,
            HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
    	HttpServletRequest req=(HttpServletRequest)request;
		HttpServletResponse resp=(HttpServletResponse)response;
		String str = req.getRequestURI();
		HttpSession session=req.getSession();
		String contextPath=session.getServletContext().getContextPath();
		AdminBeanW admin=(AdminBeanW)session.getAttribute("admin");

		if(str.indexOf("login")!=-1||str.indexOf("image")!=-1||admin!=null){
			filterChain.doFilter(request, response);
		}
		else{
			String fpath=contextPath+"/jsp/login.jsp";
			resp.sendRedirect(fpath);
		}
       
        }
    }
  
